import java.io.File;


public class PrepareResourceFileNames {

    final static File DIR = new File("C:/tmp/x/shops/icons/");
    
    /**
     * @param args
     */
    public static void main ( String[] args ) 
    {
        File[] files = DIR.listFiles();
        for ( File file : files )
        {
            String name = file.getName();
            String newName = mkValidResName(name);
            String tmpName = "__" + newName;
            System.out.println(name + " --> " + tmpName + " --> " + newName);
            File tmpFile = rename(file,tmpName);
            rename(tmpFile,newName);
        }
    }
    
    static String mkValidResName ( String name ) {
        String tmpName = name.toLowerCase();
        String androidName = "";
        for ( int i = 0; i < tmpName.length(); i++ ) {
            char c = tmpName.charAt(i);
            if ( Character.isLetterOrDigit(c) || c == '.' ) 
                androidName += c;
        }
        return androidName; 
    }

    private static File rename ( File file, String newName )
    {
        File f = new File(DIR,newName);
        boolean res = file.renameTo(f);
        if ( res == false )
            throw new RuntimeException("Could not rename '" + file.getName() + "' to '" + newName + "'");
        return f;
    }
}
